export function getRenderColor(betKey) {
    let color;
    switch (betKey) {
        case "b_a":
        case "r_a":
            color = "#AD4939";
            break;
        case "b_b":
        case "r_b":
            color = "#C66952";
            break;
        case "b_m":
        case "r_m":
            color = "#D6826B";
            break;
        case "b_s":
        case "r_s":
            color = "#EF967B";
            break;
        case "c":
        case "cl":
            color = "#8CBE8C";
            break;
        case "f":
            color = "#6BA2C6";
            break;
    }
    return color;
}

const mapBet = {
    b_a: "All in",
    r_a: "All in",
    b_b: "Bet 72%",
    r_b: "R 120%",
    b_m: "Bet 50%",
    r_m: "R 72%",
    b_s: "Bet 28%",
    r_s: "R 50%",
    c: "Check",
    cl: "Call",
    f: "Fold",
};

export function getBetDesc(betKey) {
    return mapBet[betKey];
}

export function getSuitArray(hand) {
    let suitArray;
    if (hand[0] == hand[1]) {
        suitArray = [
            ["s", "d"],
            ["s", "c"],
            ["s", "h"],
            ["d", "c"],
            ["d", "h"],
            ["c", "h"],
        ];
    } else if (hand[2] == "o") {
        suitArray = [
            ["s", "d"],
            ["s", "c"],
            ["s", "h"],
            ["d", "s"],
            ["d", "c"],
            ["d", "h"],
            ["c", "s"],
            ["c", "d"],
            ["c", "h"],
            ["h", "s"],
            ["h", "d"],
            ["h", "c"],
        ];
    } else {
        suitArray = [
            ["s", "s"],
            ["d", "d"],
            ["c", "c"],
            ["h", "h"],
        ];
    }
    return suitArray;
}

export function accumulateBetAndCombo(descKey, strategy, strategyBoardHand) {
    let combos = strategyBoardHand.combos;
    if (!strategyBoardHand.desc[descKey]) {
        if (!strategy[`no_${descKey}`]) {
            strategy[`no_${descKey}`] = {
                combos: combos,
                bet: {},
            };
            for (let betKey in strategyBoardHand.bet) {
                strategy[`no_${descKey}`].bet[betKey] =
                    strategyBoardHand.bet[betKey] * combos;
            }
        } else {
            strategy[`no_${descKey}`].combos += combos;
            for (let betKey in strategy[`no_${descKey}`].bet) {
                strategy[`no_${descKey}`].bet[betKey] =
                    strategy[`no_${descKey}`].bet[betKey] +
                    strategyBoardHand.bet[betKey] * combos;
            }
        }
    } else {
        for (let makeKey in strategyBoardHand.desc[descKey]) {
            if (!strategy[makeKey]) {
                strategy[makeKey] = {
                    combos: combos,
                    bet: {},
                };
                for (let betKey in strategyBoardHand.bet) {
                    strategy[makeKey].bet[betKey] =
                        strategyBoardHand.bet[betKey] * combos;
                }
            } else {
                strategy[makeKey].combos += combos;
                for (let betKey in strategy[makeKey].bet) {
                    strategy[makeKey].bet[betKey] =
                        strategy[makeKey].bet[betKey] +
                        strategyBoardHand.bet[betKey] * combos;
                }
            }
        }
    }
}

export let suitToEmoji = {
    s: {
        emoji: "♠",
        color: "black",
    },
    h: {
        emoji: "❤",
        color: "red",
    },
    c: {
        emoji: "♣",
        color: "green",
    },
    d: {
        emoji: "♦︎",
        color: "blue",
    },
};

export let makeOrder = [
    "royal_flush_straight",
    "flush_straight",
    "quards",
    "full_house",
    "flush",
    "nut_flush",
    "second_flush",
    "straight",
    "nut_straight",
    "b_straight",
    "set",
    "t_set",
    "m_set",
    "b_set",
    "trips",
    "two_pair",
    "t_two_pair",
    "m_two_pair",
    "b_two_pair",
    "o_pair",
    "o_pair_aa",
    "o_pair_kk",
    "t_pair",
    "t_pair_tk",
    "t_pair_sk",
    "t_pair_mk",
    "t_pair_wk",
    "t2m_pair",
    "m_pair",
    "m_pair_tk",
    "m_pair_sk",
    "m_pair_mk",
    "m_pair_wk",
    "m2b_pair",
    "b_pair",
    "b_pair_tk",
    "b_pair_sk",
    "b_pair_mk",
    "b_pair_wk",
    "w_pair",
    "a_high",
    "k_high",
    "no_make",
];

export let drawOrder = [
    "flush_d",
    "oesd",
    "overcard",
    "gut_shot",
    "t_gut_shot",
    "b_gut_shot",
    "bd_flush",
    "no_draw",
];

const mapMake = {
    royal_flush_straight: "皇家同花顺",
    flush_straight: "同花顺",
    quards: "四条",
    full_house: "葫芦",
    flush: "同花",
    nut_flush: "坚果同花",
    second_flush: "第二坚果同花",
    straight: "顺子",
    nut_straight: "上顺",
    b_straight: "下顺",
    set: "暗三条",
    t_set: "顶暗三",
    m_set: "中暗三",
    b_set: "底暗三",
    trips: "明三条",
    two_pair: "两对",
    t_two_pair: "顶两对",
    m_two_pair: "中两对",
    b_two_pair: "底两队",
    o_pair: "超对",
    o_pair_aa: "AA",
    o_pair_kk: "KK",
    t_pair: "顶对",
    t_pair_tk:"顶对顶踢",
    t_pair_sk:"顶对大踢",
    t_pair_mk:"顶对中踢",
    t_pair_wk:"顶对弱踢",
    t2m_pair: "顶对中对之间",
    m_pair: "中对",
    m_pair_tk:"中对顶踢",
    m_pair_sk:"中对大踢",
    m_pair_mk:"中对中踢",
    m_pair_wk:"中对弱踢",
    m2b_pair: "中对底对之间",
    b_pair: "底对",
    b_pair_tk:"底对顶踢",
    b_pair_sk:"底对大踢",
    b_pair_mk:"底对中踢",
    b_pair_wk:"底对弱踢",
    w_pair: "弱对",
    a_high: "A高牌",
    k_high: "K高牌",
    no_make: "没有成牌",
};

export function getMakeDesc(makeKey) {
    return mapMake[makeKey];
}

const mapDraw = {
    flush_d: "同花听牌",
    oesd: "两头顺",
    over_card: "两高张",
    gut_shot: "卡顺",
    t_gut_shot: "顶卡顺",
    b_gut_shot: "底卡顺",
    bd_flush: "后门花",
    no_draw: "没有听牌",
};

export function getDrawDesc(makeKey) {
    return mapDraw[makeKey];
}


export function flopBoardHtml(flopBoard){
    if(!flopBoard){
        return ''
    }
    return (
        `<span style="color:${suitToEmoji[flopBoard[1]].color}">${
            flopBoard[0]
        }${suitToEmoji[flopBoard[1]].emoji}</span>` +
        `<span style="color:${suitToEmoji[flopBoard[3]].color}">${
            flopBoard[2]
        }${suitToEmoji[flopBoard[3]].emoji}</span>` +
        `<span style="color:${suitToEmoji[flopBoard[5]].color}">${
            flopBoard[4]
        }${suitToEmoji[flopBoard[5]].emoji}</span>`
    );
}